<extend name="Public/layout"/>
<block name="head">
    <title>送你现金红包，来{$platform.name}一起安心理财！</title>
    <link rel="stylesheet" href="__PUBLIC__css/mobile-reset.css"/>
    <link rel="stylesheet" href="__PUBLIC__css/mobile-register.css"/>
    <link rel="stylesheet" href="__PUBLIC__css/m_marketing.css"/>
    <link rel="stylesheet" href="__PUBLIC__css/animate.css"/>
    <style type="text/css">
        .footer {
            display: none;
        }
    </style>
    <script src="http://static.geetest.com/static/tools/gt.js"></script>
    <script type="text/javascript" src="__PUBLIC__js/md5.js"></script>
    <script type="text/javascript" src="__PUBLIC__js/redBag.js"></script>
    <script src="__PUBLIC__assets/better-scroll/bscroll.min.js"></script>
</block>
<block name="main">
<div class="first-screen-header" style="    height: 17rem;">
    <div class="first-screen">
        <div class="top-pocket-wrapper">
            <div class="info-wrapper">
                <p>投资合作平台</p>
                <p>最高可得<span>{$platform.0.user_award}</span>元现金红包</p>
            </div>
            <div class="avatar-wrapper">
                <div class="avatar">
                    <img src="{$u_info.url_img}" alt="">
                </div>
                <div class="user-info">
                    <p>
                        <span class="username">{$u_info.nickname}</span>
                    </p>
                    <p>邀请您到8号金融街投资赚红包啦！</p>
                </div>
            </div>
            <div class="input-wrapper">
                <input type="text" name="phone" onblur="checkform()" placeholder="输入手机号码">
            </div>
            <div class="form-group">
                <input type="text" name="code" onblur="checkform(3)" placeholder="请输入验证码">
                <div class="phone-text-wrapper">
                    <button  onclick="getcode()">获取验证码</button>
                </div>
            </div>
            <div class="input-wrapper">
                <input type="password" name="password" onblur="checkform(4)" placeholder="请设置8号金融街返利账户登录密码">
            </div>
            <div class="btn-wrapper">
                <a href="javascript:"  onclick="sub()" class="btn">领取红包</a>
            </div>
        </div>
    </div>    
</div>
<div class="step">
        <div class="step-title">获得返利流程</div>
        <div class="step-content">
            <ul>
                <li>
                <p class="item-icon"><i class="icon_zhuc"></i></p>
                    
                    <p>注册8号金融街返利账户</p>
                </li>
                 <li class="tips"><img src="__PUBLIC__images/icon_wd_r_nor@2x.png" alt=""></li>
                <li>
                     <p class="item-icon"><i class="icon_touzi"></i></p>
                    <p>投资合作平台的返利标的</p>
                </li>
               <li class="tips"><img src="__PUBLIC__images/icon_wd_r_nor@2x.png" alt=""></li>
                <li>
                    <p class="item-icon"><i class="icon_tixian"></i></p>
                    <p>返利将自动提现到8号金融街绑定银行卡</p>
                </li>                                
            </ul>         
        </div>
</div>
<div class="rule">
    <div class="rule-title">活动规则</div>
    <div class="rule-content">
        <p>1、通过平台专属链接投资或出借。</p>
        <p>2、满足起投金额及相关奖励门槛。</p>
        <p>3、首投用户需是之前没有在任何渠道注册过的平台新用户。</p>
        <p>4、首投是通过8号金融街进行的才能领取复投奖励。</p>
    </div>
</div>
<div class="tips">网贷理财有风险，投资出借需谨慎</div>
<!-- 弹窗 -->
<div class="container" id="container" style="display:none">
<!-- 弹红包 -->
    <div class="hongbao">
        <div class="topcontent" >
            <div class="close"></div>
            <div class="avatar"><img src="{$u_info.url_img}" alt=""></div>
            <h2>{$u_info.nickname}</h2>
            <P class="text">给您送红包啦！</p>
            <div class="description">恭喜发财，大吉大利</div>
        </div>
        <div class="chai" id="chai">
        </div>
    </div>
    <!-- 红包打开后 -->
    <div class="hongbao-open animated zoomIn" style="display:none">
        <div class="close" id="close-all"></div>
        <div class="open-text">
            <p>恭喜您获得以下现金红包，</p>
            <p>前往合作平台投资即可领取现金红包</p>
        </div>
        <div class="open-content">
            <ul>
            <foreach name="platform" item="v">
                <li>
                    <div class="open-content-item">
                        <div class="content-item-left">
                           <img src="{$v.pic}" alt="">
                        </div>
                        <div class="content-item-rgiht">
                            <div class="pro-bottom-left">
                                <dd><i>{$v.user_award}</i>元</dd>
                                <dd>首投最高返利</dd>
                            </div>
                            <div class="pro-bottom-left">
                                <dd>{:ceil($v['start_amount'])}元</dd>
                                <dd>起投金额</dd>
                            </div>                            
                        </div>
                    </div>
                </li>
            </foreach>
              
             
             
            </ul>
        </div>
        <div class="login"><button>去注册领红包</button></div>
    </div>
</div>
</block>
<block name="js">
    <script>
        var check = false;
        var checkphone = false;
        var code_check = false;
        var pass_check = false;
        var r_msg = "填写有误请检查后在提交";
        function checkform(val){
            var phone = $('input[name="phone"]').val();
            // 手机为空的情况
            if (!phone) {
                msg = "手机号不能为空";
                check = false;
                layer.closeAll();
                layer.open({
                    content: msg
                    , skin: 'msg'
                    , time: 1
                });
                return;
            }
//            手机不为空，做校验
            if (!(/^1[3|7|4|5|8][0-9]\d{4,8}$/.test(phone))) {
                msg = "手机号码错误！";
                check = false;
                layer.closeAll();
                layer.open({
                    content: msg
                    , skin: 'msg'
                    , time: 1
                });
                return;
            } else {
                //验证手机是否存在
                $.post("{:U('User/checkphone')}", {
                    phone: phone,
                }, function (res) {
                    if (res.err == 1) {
                        checkphone = false;
                        layer.closeAll();
                        layer.open({
                            content: res.msg
                            , skin: 'msg'
                            , time: 1
                        });
                    } else {
                        checkphone = true;
                    }
                })
            }

            if(checkphone && val==3){
                var code = $('input[name="code"]').val();
                if (!code) {
                    msg = "短信验证码不能为空";
                    code_check = false;
                    layer.closeAll();
                    layer.open({
                        content: msg
                        , skin: 'msg'
                        , time: 1
                    });
                    return
                } else {
                    code_check = true;
                }
            }

            if (checkphone && val==4) {
                var password = $('input[name="password"]').val();
                if (!password) {
                    msg = "密码不能为空";
                    pass_check = false;
                    layer.closeAll();
                    layer.open({
                        content: msg
                        , skin: 'msg'
                        , time: 1
                    });
                    return
                } else {
                    pass_check = true;
                }
            }

            if (checkphone && code_check && pass_check) {
                check = true;
            } else {
                check = false;
                r_msg = "填写有误请检查后在提交！";
            }
        }


        function getcode() {
            console.log(checkphone)
            if (checkphone) {
                event_send_sms()
            } else {
                layer.open({
                    content: "手机号码填写不正确！"
                    , skin: 'msg'
                    , time: 1
                });
            }
        }

        //验证码计时
        var timer = 60;

        //发送短信
        function event_send_sms() {
            var postData = {
                phone: $('input[name="phone"]').val()
            }
            if (timer >= 60) {
                var phone = $('input[name="phone"]').val();
                $(this).attr('disabled', 'disabled');
                $.ajax({
                    url: '/Home/User/send_sms_reg',
                    data: postData,
                    type: "post",
                    dataType: "json",
                    success: function (d) {
                        if (d.err == 0) {
                            codeTimer();
                        } else {
                            layer.open({
                                content: d.msg
                                , skin: 'msg'
                                , time: 1
                            });
                        }
                    }
                });

            }
        }



        function codeTimer() {
            timer--;
            if (timer > 0) {
                $('.phone-text-wrapper button').removeClass("active").addClass("disable");
                $('.phone-text-wrapper button').html(timer + '秒后可重发!');
                setTimeout('codeTimer()', 1000);
            } else {
                $('.phone-text-wrapper button').html('获取验证码');
                $('.phone-text-wrapper button').addClass("active").removeClass("disable");
                timer = 60;
            }
        }


        //注册
        function sub() {
            if (check) {
                var phone = $('input[name="phone"]').val();
                var code = $('input[name="code"]').val();
                var password = $('input[name="password"]').val();
                var referral = "{$_GET['recommend_id']}";
                var password = $.md5(password);
                $.post('{:U("User/check_register")}', {
                    phone: phone,
                    password: password,
                    code: code,
                    referral: referral,
                }, function (res) {
                    if (res.err == 0) {
                        //    layer.msg(res.msg,{time:500},function(){location.href="/Home/Platform/bind_platform/id/{$_GET['p_id']}"});
                        layer.closeAll();
                        layer.open({
                            content: res.msg
                            , skin: 'msg'
                            , time: 1
                            , end: function () {
                                location.href = "/Home/Financial/index"
                            }
                        });


                    } else {
                        layer.closeAll();
                        layer.open({
                            content: res.msg
                            , skin: 'msg'
                            , time: 1
                        });
                    }
                })
            } else {
                if (!checkphone) {
                    r_msg = '请检查输入的手机号码是否有误'
                    layer.closeAll();
                    layer.open({
                        content: r_msg
                        , skin: 'msg'
                        , time: 1
                    });
                    return;
                }
                if (!code_check) {
                    r_msg = '短信验证码不能为空'
                    layer.closeAll();
                    layer.open({
                        content: r_msg
                        , skin: 'msg'
                        , time: 1
                    });
                    return;
                }
                if (!pass_check) {
                    r_msg = '密码不能为空'
                    layer.closeAll();
                    layer.open({
                        content: r_msg
                        , skin: 'msg'
                        , time: 1
                    });
                    return;
                }
                layer.closeAll();
                layer.open({
                    content: r_msg 
                    , skin: 'msg'
                    , time: 1
                });
            }
        }

        var title="送你现金返利，来8号金融街一起安心理财！首投可得{$platform.0.user_award}元！"
        var desc = '精选优质理财产品，安全度更高、总收益更多、让投资变得更容易，来8号金融街一起理财吧~！'
        var link=window.location.href
        var imgUrl='http://www.8hjie.com/App/Home/Public/images/wx_fx.jpg'

        // 弹窗
        $('#chai').click(function() {
            $(this).removeClass('chai').addClass('rotate');
            setInterval(function(){
                $(".hongbao").hide();
                $('.hongbao-open').css('display','block');
            },1000)
        });
        $(".hongbao >.topcontent > .close").click(function() {
             $("#container").hide();
             $('body').css('overflow','');
        });
        $(".hongbao-open > .close").click(function() {
             $("#container").hide();
             $('body').css('overflow','');
        });
        $(".login > button").click(function() {
             $("#container").hide();
             $('body').css('overflow','');
        });        
        $(function(){
            var user_id = "{$_SESSION['user']['id']}"
            console.log(user_id)
            var push_id = "{$_GET['recommend_id']}"
            if(user_id != push_id){
                    $("#container").show();
                    $('body').css('overflow','hidden');
            }
            
        });
    </script>
</block>